//================v1要点总结===============
/**
 * 1. 采用层序遍历的思想，对不上的节点赋值为0
 */

/**
 * Definition for a binary tree node.
 */
function TreeNode(val, left, right) {
    this.val = (val === undefined ? 0 : val)
    this.left = (left === undefined ? null : left)
    this.right = (right === undefined ? null : right)
}
/**
 * @param {TreeNode} root1
 * @param {TreeNode} root2
 * @return {TreeNode}
 */
var mergeTrees = function (root1, root2) {
    let arr1 = [root1]
    let arr2 = [root2]
    let rslt = root1 || root2
    while (arr1.length) {
        let tempNode1 = arr1.shift()
        let tempNode2 = arr2.shift()
        if (!tempNode1 && !tempNode2) {
            continue
        }
        if (tempNode1 && !tempNode2) {
            tempNode2 = new TreeNode()
        } else if (!tempNode1 && tempNode2) {
            tempNode1 = new TreeNode()

        }
        tempNode1.val += tempNode2.val
        if (!tempNode1.left && tempNode2.left) {
            tempNode1.left = new TreeNode()
        }

        if (!tempNode1.right && tempNode2.right) {
            tempNode1.right = new TreeNode()
        }

        arr1.push(tempNode1.left)
        arr1.push(tempNode1.right)
        arr2.push(tempNode2.left)
        arr2.push(tempNode2.right)
    }
    return rslt
};

console.log(3, mergeTrees())